const fs = require('fs');
const path = require('path');

const {
  PICTURES_PATH, 
} = require('../constants/file-path');

class FileController {
  // 获取图片文件流
  async getImgByPath(ctx, next) {
    const {imgName} = ctx.params;
    const theEnd = path.extname(imgName).split('.');

    ctx.response.set('content-type', `image/${theEnd[theEnd.length - 1]}`);
    ctx.body = fs.createReadStream(`${PICTURES_PATH}/${imgName}`);
  }
}

module.exports = new FileController();